package com.springboot.mybatis.service.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author sunyt31481
 * @date 2020/8/12 16:50
 * @description FanOut 广播模型，使用到交换机进行传递消息，实现一条消息被多个消费者消费
 */
public class ProduceFanOutDemo {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connect = RabbitMqUtil.getConnect();
        Channel channel = connect.createChannel();
        //将通道声明指定交换机，参数1：交换机名称  参数2：广播方式
        channel.exchangeDeclare("logs", "fanout");
        //发送消息，只考虑交换机，不考虑队列了
        //第二个参数为路由键，暂未用到 RouteKey
        channel.basicPublish("logs", "",null,"hello FanOut".getBytes());

        RabbitMqUtil.closeConnect(channel, connect);
    }
}
